package org.zxl.api.common.dto;

/**
 * @author zhangxiaolong
 * @date 2025-02-17 16:50
 **/
public class CloudResponseEntity<R> {

    /**
     * 操作结果
     * */
    private Boolean result;

    /**
     * 返回结果
     * */
    private R data;

    /**
     * 返回code
     * */
    private String code;

    /**
     * 错误信息
     * */
    private String errorMsg;

    /**
     * 出现异常的url或者方法；错误时有值。
     */
    private String errorUrlOrMethod;

    public Boolean getResult() {
        return result;
    }

    public void setResult(Boolean result) {
        this.result = result;
    }

    public R getData() {
        return data;
    }

    public void setData(R data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getErrorUrlOrMethod() {
        return errorUrlOrMethod;
    }

    public void setErrorUrlOrMethod(String errorUrlOrMethod) {
        this.errorUrlOrMethod = errorUrlOrMethod;
    }

    public CloudResponseEntity(R data) {
        this.result = true;
        this.data = data;
    }

    public CloudResponseEntity(String code, String errorMsg, String errorUrlOrMethod) {
        this.code = code;
        this.errorMsg = errorMsg;
        this.errorUrlOrMethod = errorUrlOrMethod;
    }

    public static <R>CloudResponseEntity<R> success(R data) {
        CloudResponseEntity<R> cloudResponseEntity = new CloudResponseEntity<R>(data);
        cloudResponseEntity.setData(data);
        cloudResponseEntity.setResult(true);
        return cloudResponseEntity;
    }

    public static CloudResponseEntity<Void> error(String code, String errorMsg, String errorUrlOrMethod) {
        CloudResponseEntity<Void> cloudResponseEntity = new CloudResponseEntity<Void>(code, errorMsg, errorUrlOrMethod);
        cloudResponseEntity.setResult(false);
        return cloudResponseEntity;
    }

    public static void main(String[] args) {
        CloudResponseEntity<Void> cloudResponseEntity = CloudResponseEntity.error("123", "error", "errorUrlOrMethod");
        System.out.println(cloudResponseEntity.toString());
    }


}
